//
//  WaKuangInfoVC.m
//  digitalCurrency
//
//  Created by 小震GG on 2019/11/6.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "WaKuangInfoVC.h"
#import "NewAllNetManager.h"
#import "WMHTMLViewController.h"
@interface WaKuangInfoVC ()

@property (nonatomic, strong) UILabel *leiJiLB;
@property (nonatomic, strong) UILabel *jinRiLB;

@property (nonatomic, strong) UILabel *bianHaoLB;
@property (nonatomic, strong) UILabel *shiJianLB;
@property (nonatomic, strong) UIView *suanLiView;
@property (nonatomic, strong) UILabel *suanLiLB;
@property (nonatomic, strong) UIView *nanDuView;
@property (nonatomic, strong) UILabel *nanDuLB;

@property (nonatomic, strong) NSDictionary *dataDic;
@end

@implementation WaKuangInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.viewTitle.text = LocalizationKey(@"挖矿");
    self.dataDic = [[NSDictionary alloc]init];
    
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:LocalizationKey(@"运行状态") style:UIBarButtonItemStylePlain target:self action:@selector(rightBtnAct)];
    self.navigationItem.rightBarButtonItem = rightBarItem;
    rightBarItem.tintColor = [UIColor whiteColor];
    
    [self setView];
    
    [self loadData];
}

- (void)rightBtnAct{
    WMHTMLViewController *aboutC = [[WMHTMLViewController alloc]init];
    CGFloat bottomH     = kEasyShowSafeBottomMargin_S;
    aboutC.webViewRect  = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - kTopHeight - bottomH);
    aboutC.canScroll                = YES;
    aboutC.showProgressView         = YES;
    aboutC.hidesBottomBarWhenPushed = YES;
    aboutC.webViewTitle = LocalizationKey(@"运行状态");
    aboutC.htmlUrl = @"https://torchex.global/swan/index.html";
    [self.navigationController pushViewController:aboutC animated:YES];
}

- (void)loadData{
    [NewAllNetManager KuangJiInfo:self.idStr CompleteHandle:^(id  _Nonnull resPonseObj, int code) {
        if (code) {
            NSInteger codeInt = [resPonseObj[@"code"] intValue];
            if (codeInt == 0) {
                self.dataDic = resPonseObj[@"data"];
                
                self.leiJiLB.text = [NSString stringWithFormat:@"%@\n%@",self.dataDic[@"currencyTotal"],LocalizationKey(@"累计产币")];
                self.jinRiLB.text = [NSString stringWithFormat:@"%@\n%@",self.dataDic[@"currencyToday"],LocalizationKey(@"今日产币")];
                self.bianHaoLB.text = [NSString stringWithFormat:@"%@",self.dataDic[@"millNum"]];
                self.shiJianLB.text = [NSString stringWithFormat:@"%@",self.dataDic[@"createTime"]];
                self.suanLiLB.text = [NSString stringWithFormat:@"%@/%@",self.dataDic[@"myCalculation"],LocalizationKey(@"365天")];
                self.nanDuLB.text = [NSString stringWithFormat:@"%@",self.dataDic[@"DifficultyToday"]];

                float suanLiF = [[NSString stringWithFormat:@"%@",self.dataDic[@"myCalculation"]] floatValue];
                float nanDuF = [[NSString stringWithFormat:@"%@",self.dataDic[@"DifficultyToday"]] floatValue];

                [self.suanLiView mas_remakeConstraints:^(MASConstraintMaker *make) {
                          make.left.top.bottom.equalTo(0);
                          make.width.equalTo(suanLiF/365.0*(kWindowW-140));
                }];
                [self.nanDuView mas_remakeConstraints:^(MASConstraintMaker *make) {
                       make.left.top.bottom.equalTo(0);
                       make.width.equalTo(nanDuF/1.0*(kWindowW-140));
                }];
            }
        }
    }];
}

- (void)setView{
    
    UIView *bgView = [[UIView alloc]init];
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.top.equalTo(0);
        make.right.equalTo(0);
        make.height.equalTo(202);
    }];
    bgView.backgroundColor = tMainColor;
    
    UIImageView *logoImage = [[UIImageView alloc]init];
    [bgView addSubview:logoImage];
    [logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(0);
        make.top.equalTo(5);
    }];
    logoImage.image = ImageName(@"wakuang_logo");
    
    UILabel *waLB = [[UILabel alloc]init];
    [bgView addSubview:waLB];
    [waLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(0);
        make.top.equalTo(logoImage.mas_bottom).offset(16);
    }];
    waLB.textColor = [UIColor whiteColor];
    waLB.font = kFont(16);
    waLB.text = LocalizationKey(@"正在挖矿...");
    
    UIView *bottomView = [[UIView alloc]init];
    [bgView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(0);
        make.bottom.equalTo(-7);
        make.height.equalTo(50);
    }];
    bottomView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.08];
    
    UIView *shuLineView = [[UIView alloc]init];
    [bottomView addSubview:shuLineView];
    [shuLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(0);
        make.width.equalTo(1);
        make.height.equalTo(31);
    }];
    shuLineView.backgroundColor = [UIColor whiteColor];
    
    self.leiJiLB = [[UILabel alloc]init];
    [bottomView addSubview:self.leiJiLB];
    [self.leiJiLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(0);
        make.width.equalTo(kWindowW/2.0);
    }];
    self.leiJiLB.numberOfLines = 0;
    self.leiJiLB.textColor = [UIColor whiteColor];
    self.leiJiLB.font = kFont(14);
    self.leiJiLB.textAlignment = NSTextAlignmentCenter;
    self.leiJiLB.text = [NSString stringWithFormat:@"00.00\n%@",LocalizationKey(@"累计产币")];
    
    self.jinRiLB = [[UILabel alloc]init];
    [bottomView addSubview:self.jinRiLB];
    [self.jinRiLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(0);
        make.width.equalTo(kWindowW/2.0);
    }];
    self.jinRiLB.numberOfLines = 0;
    self.jinRiLB.textColor = [UIColor whiteColor];
    self.jinRiLB.font = kFont(14);
    self.jinRiLB.textAlignment = NSTextAlignmentCenter;
    self.jinRiLB.text = [NSString stringWithFormat:@"00.00\n%@",LocalizationKey(@"今日产币")];
    
    UILabel *bianHaoTitleLB = [[UILabel alloc]init];
    [self.view addSubview:bianHaoTitleLB];
    [bianHaoTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(27);
        make.top.equalTo(bgView.mas_bottom).offset(40);
    }];
    bianHaoTitleLB.textColor = [UIColor colorWithHEX:@"#9FB0BD"];
    bianHaoTitleLB.font = kFont(12);
    bianHaoTitleLB.text = LocalizationKey(@"编号");
    
    self.bianHaoLB = [[UILabel alloc]init];
    [self.view addSubview:self.bianHaoLB];
    [self.bianHaoLB mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.equalTo(110);
           make.centerY.equalTo(bianHaoTitleLB);
    }];
    self.bianHaoLB.textColor = tThreeColor;
    self.bianHaoLB.font = kFont(12);
    self.bianHaoLB.text = @"0";
    
    
    UILabel *shiJianTitleLB = [[UILabel alloc]init];
    [self.view addSubview:shiJianTitleLB];
    [shiJianTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(27);
        make.top.equalTo(bianHaoTitleLB.mas_bottom).offset(35);
    }];
    shiJianTitleLB.textColor = [UIColor colorWithHEX:@"#9FB0BD"];
    shiJianTitleLB.font = kFont(12);
    shiJianTitleLB.text = LocalizationKey(@"启动时间");
    
    self.shiJianLB = [[UILabel alloc]init];
    [self.view addSubview:self.shiJianLB];
    [self.shiJianLB mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.equalTo(110);
           make.centerY.equalTo(shiJianTitleLB);
    }];
    self.shiJianLB.textColor = tThreeColor;
    self.shiJianLB.font = kFont(12);
    
    
    UILabel *suanLiTitleLB = [[UILabel alloc]init];
    [self.view addSubview:suanLiTitleLB];
    [suanLiTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(27);
        make.top.equalTo(shiJianTitleLB.mas_bottom).offset(35);
    }];
    suanLiTitleLB.textColor = [UIColor colorWithHEX:@"#9FB0BD"];
    suanLiTitleLB.font = kFont(12);
    suanLiTitleLB.text = LocalizationKey(@"算力贡献");
    
    UIView *suanLiViwe = [[UIView alloc]init];
    [self.view addSubview:suanLiViwe];
    [suanLiViwe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(110);
        make.centerY.equalTo(suanLiTitleLB);
        make.width.equalTo(kWindowW-140);
        make.height.equalTo(8);
    }];
    suanLiViwe.backgroundColor = [UIColor colorWithHEX:@"#F2F2F2"];
    suanLiViwe.layer.masksToBounds = YES;
    suanLiViwe.layer.cornerRadius = 4.0;
    
    self.suanLiView = [[UILabel alloc]init];
    [suanLiViwe addSubview:self.suanLiView];
    [self.suanLiView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.top.bottom.equalTo(0);
           make.width.equalTo(0);
    }];
    self.suanLiView.backgroundColor = tMainColor;
    
    self.suanLiLB = [[UILabel alloc]init];
    [self.view addSubview:self.suanLiLB];
    [self.suanLiLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(suanLiViwe.mas_right);
        make.top.equalTo(suanLiViwe.mas_bottom).offset(5);
    }];
    self.suanLiLB.textColor = tThreeColor;
    self.suanLiLB.font = kFont(9);
    
    
    UILabel *nanDuTitleLB = [[UILabel alloc]init];
    [self.view addSubview:nanDuTitleLB];
    [nanDuTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(27);
        make.top.equalTo(suanLiTitleLB.mas_bottom).offset(35);
    }];
    nanDuTitleLB.textColor = [UIColor colorWithHEX:@"#9FB0BD"];
    nanDuTitleLB.font = kFont(12);
    nanDuTitleLB.text = LocalizationKey(@"今日难度");
    
    UIView *nanDuViwe = [[UIView alloc]init];
    [self.view addSubview:nanDuViwe];
    [nanDuViwe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(110);
        make.centerY.equalTo(nanDuTitleLB);
        make.width.equalTo(kWindowW-140);
        make.height.equalTo(8);
    }];
    nanDuViwe.backgroundColor = [UIColor colorWithHEX:@"#F2F2F2"];
    nanDuViwe.layer.masksToBounds = YES;
    nanDuViwe.layer.cornerRadius = 4.0;
    
    self.nanDuView = [[UILabel alloc]init];
    [nanDuViwe addSubview:self.nanDuView];
    [self.nanDuView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.top.bottom.equalTo(0);
           make.width.equalTo(0);
    }];
    self.nanDuView.backgroundColor = [UIColor colorWithHEX:@"#FF6D00"];
    
    self.nanDuLB = [[UILabel alloc]init];
    [self.view addSubview:self.nanDuLB];
    [self.nanDuLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(nanDuViwe.mas_right);
        make.top.equalTo(nanDuViwe.mas_bottom).offset(5);
    }];
    self.nanDuLB.textColor = tThreeColor;
    self.nanDuLB.font = kFont(9);
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
